package com.scedu.service.Impl;

import com.scedu.entity.Emp;
import com.scedu.repository.EmpRepository;
import com.scedu.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;

@Service //业务层
@Transactional //事务控制
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpRepository empRepository;
    @Override
    public void save(Emp emp) {
        emp.setId(UUID.randomUUID().toString());
        empRepository.save(emp);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<Emp> findAll() {
        return empRepository.findAll();
    }

    @Override
    public void del(String id) {
        empRepository.del(id);
    }

    @Override
    public Emp find(String id) {
        return empRepository.find(id);
    }

    @Override
    public void edit(Emp emp) {
        empRepository.edit(emp);
    }
}
